import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains


# 跑通第一条用例代码
driver=webdriver.Edge()
driver.maximize_window()
driver.get('https://www.baidu.com/')
# 隐式等待
driver.implicitly_wait(1)

# 点击百度新闻  鼠标操作
sbcz=driver.find_element(By.XPATH,'//*[@id="s-top-left"]/a[1]')
# 强制等待
time.sleep(5)
ActionChains(driver).click(sbcz).perform()
# 输入框  显示等待
WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.XPATH,'//input[@class="word" or @id="ww"]'))).click()
# driver.find_element(By.XPATH,'//input[@class="word" or @id="ww"]').send_keys("北京市")
# time.sleep(5)
# 搜索按钮  键盘操作
driver.find_element(By.CSS_SELECTOR,'.btn').click()
time.sleep(5)
# 点击网页
driver.find_element(By.XPATH,'//*[@id="s_tab_inner"]/a[1]/span').click()
time.sleep(5)
# JS/滑动操作
driver.execute_script('window srcollTo(0,500)')
# 北京概括 人民之首
driver.find_element(By.CSS_SELECTOR,'tts-b-hl').click()
time.sleep(5)
# 浏览器事件
driver.refresh()